home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / Rotato / Source / rotato.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-25  |  2.8 KB  |  113 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Y2K was a hack written for MacHack 1988 by Simon Fraser and John McMullen,
  3. **    extending the original idea for Y2K from Jon Kalb.
  4. **
  5. **    Y2K was implemented by starting with the Apple DTS sample code
  6. **    The original copyright blurb appears below.
  7. */
  8.  
  9. /*
  10. **    
  11. **    Apple Macintosh Developer Technical Support
  12. **
  13. **    Sample code demonstrating how to patch PowerOff key
  14. **
  15. **    by Brian Bechtel, Apple Developer Technical Support
  16. **
  17. **    File:        PatchPowerOff.c
  18. **
  19. **    Copyright © 1995 Apple Computer, Inc.
  20. **    All rights reserved.
  21. **
  22. **    You may incorporate this sample code into your applications without
  23. **    restriction, though the sample code has been provided "AS IS" and the
  24. **    responsibility for its operation is 100% yours.  However, what you are
  25. **    not permitted to do is to redistribute the source as "DTS Sample Code"
  26. **    after having made changes. If you're going to re-distribute the source,
  27. **    we require that you make it clear in the source that the code was
  28. **    descended from Apple Sample Code, but that you've made changes.
  29. */
  30. #include <Gestalt.h>
  31. #include <Resources.h>
  32. #include <DeskBus.h>
  33. #include <Errors.h>
  34. #include <OSUtils.h>
  35. #include <Traps.h>
  36. #include <SetupA4.h>
  37. #include <A4Stuff.h>
  38.  
  39. #include "ShowInitIcon.h"
  40. #include "InstallCursorHack.h"
  41. #include "PrefResource.h"
  42. #include "rotato.h"
  43.  
  44. #define kRotatoIconID            128    /* matches the resID in the 68K Project preferences */
  45. #define kRotatoBadInstallIconID        129
  46.  
  47. #define USE_DEBUGGER_CALLS
  48.  
  49. void main(void);
  50.  
  51. #define kPi        3.1415926535898
  52.  
  53. /* main */
  54.  
  55. void main(void)
  56. {
  57.     long            oldA4;
  58.     TPrefsData    prefsData = {0};
  59.     Boolean        installedOK;
  60.     TPrefsDataPtr    globalDataPtr = nil;
  61.     OSErr        err;
  62.     
  63.     /// set up our A4 context for _this file_ 
  64.     oldA4 = SetCurrentA4();
  65.     RememberA4();
  66.     
  67.     err = PrepareServiceFragment(&prefsData);
  68.     if (err != noErr)
  69.     {
  70.         //Str255        errNum;
  71.         //NumToString(err, errNum);
  72.         //DebugStr(errNum);    
  73.         return;
  74.     }
  75.     
  76.     // allocate a sys ptr for our global data
  77.     globalDataPtr = (TPrefsDataPtr)NewPtrSys(sizeof(TPrefsData));
  78.     if (!globalDataPtr)
  79.     {
  80.         //DebugStr("\pFailed to allocate sys ptr");
  81.         return;
  82.     }
  83.     
  84.     // copy the data over
  85.     *globalDataPtr = prefsData;
  86.     
  87.     // install a gestalt value to get to the global data
  88.     err = NewGestaltValue(kDataGestaltSelector, (long)globalDataPtr);
  89.     if (err != noErr)
  90.     {
  91.         //DebugStr("\pFailed to create Gestalt selector");    
  92.         return;
  93.     }
  94.     
  95.     // now we have to call main to set up global data in the fragment
  96.     // we could also do this by exporting the global data from the fragment, I guess
  97.     err = (*globalDataPtr->setupProc)();
  98.     if (err != noErr)
  99.     {
  100.         //DebugStr("\pFailed to call SetupData");    
  101.         return;
  102.     }
  103.     
  104.     // look ma, no patches!
  105.     installedOK = InstallCursorHack(globalDataPtr);
  106.     ShowInitIcon(installedOK ? kRotatoIconID : kRotatoBadInstallIconID, true);
  107.     
  108.     // restore the a4 world
  109.     SetA4(oldA4);
  110.     
  111.     //DebugStr("\pDone INIT code");
  112. }
  113.